#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    string minWindow(string s, string t) {
        // if(s.size()<t.size())
        //     return string();

        map<char, int> mt;
        map<char, int> ms;

        for (auto it : t)
            mt[it]++;
        int Tcount = mt.size();
        int len = INT_MAX;
        int ll = -1;
        for (int left = 0, right = 0, count = 0; right < s.size(); right++)
        {
            ms[s[right]]++;
            if (ms[s[right]] == mt[s[right]]) count++;
            if (count == Tcount)
            {
                while (mt[s[left]] == 0 && left < right)
                    left++;
                while (ms[s[left]] > mt[s[left]])
                {
                    ms[s[left]]--;
                    left++;
                }
                if (right - left + 1 < len)
                {
                    len = right - left + 1;
                    ll = left;
                }
                while (count == Tcount)
                {
                    if (ms[s[left]]-- == mt[s[left]])
                        count--;
                    left++;
                }

            }
        }
        if (ll == -1)
            return string();
        string temp(s, ll, len);
        // for(auto it:mt)
        //     cout<<it.first<<it.second<<endl;
        return temp;

    }
};